package com.tanhua.dubbo.api.impl.mongo;

import com.tanhua.domain.mongo.FollowUser;
import com.tanhua.dubbo.api.mongo.FollowUserApi;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

@Service
public class FollowUserApiImpl implements FollowUserApi {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public void save(FollowUser followUser) {
        mongoTemplate.insert(followUser);
    }

    //取消关注的用户
    @Override
    public void unfollowUser(Long userId, Long followUserId) {
        Query query = new Query(Criteria.where("userId").is(userId).and("followUserId").is(followUserId));
        mongoTemplate.remove(query,FollowUser.class);
    }
}
